/*
 * @Author: your name
 * @Date: 2021-12-23 10:45:29
 * @LastEditTime: 2022-01-24 10:51:18
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue\vue-douban-pc\src\utils\axios.js
 */
import axios from 'axios';
import {getToken} from '@/utils/auth';
// import { MessageBox } from 'element-ui';

//请求拦截器
axios.interceptors.request.use(
    config => {
        //在发送请求之前做些什么
        config.baseURL = process.env.VUE_APP_URL //根据环境变量自动匹配baseurl
        let tokenInfo = getToken();
        if(tokenInfo){
            // tokenInfo = JSON.parse(tokenInfo);
            config.headers['Authorization'] = tokenInfo.token;
        }
        return config;
    },
    error => {
        //对请求错误做出反馈
        return Promise.reject(error);
    }
);